//
//  H5BaseViewController.m
//  didacar
//
//  Created by 度周末网络-王腾 on 15/11/27.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "H5BaseViewController.h"
#import "UIScreen+Frame.h"
#import "NJKWebViewProgress.h"
#import "NJKWebViewProgressView.h"

@interface H5BaseViewController () <NJKWebViewProgressDelegate,UIWebViewDelegate>
@property (strong, nonatomic) NJKWebViewProgress *progressProxy;
@property (strong, nonatomic) NJKWebViewProgressView *progressView;
@end

@implementation H5BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    self.navigationItem.title = self.navigationItemtitle;
    [self initWebView];
    
    [self setLeftBtnItem];
    
    [self loadWebView];
    
    [self initProgress];
}

-(void)initProgress{
    self.progressProxy = [[NJKWebViewProgress alloc] init];
    self.webView.delegate = self.progressProxy;
    self.progressProxy.webViewProxyDelegate = self;
    self.progressProxy.progressDelegate = self;
    
    self.progressView = [[NJKWebViewProgressView alloc] initWithFrame:CGRectMake(0, self.navigationController.navigationBar.bounds.size.height - 2.0, self.view.bounds.size.width, 2.0)];
    [self.progressView setProgress:0.0];
    [self.navigationController.navigationBar addSubview:_progressView];
}

-(void)initWebView{
    self.webView = [[UIWebView alloc ] initWithFrame:CGRectMake(0, 0, [UIScreen width], [UIScreen height]-64)];
    self.webView.delegate = self;
    self.webView.backgroundColor = GLOBLE_BACKGROUND_COLOR;
    self.webView.scalesPageToFit = YES;
    [self.view addSubview:self.webView];
}

-(void)dealloc{
    self.webView.delegate = nil;
    self.progressProxy.webViewProxyDelegate = nil;
    self.progressProxy.progressDelegate = nil;
    [self.progressView removeFromSuperview];
}

#pragma mark - NJKWebViewProgressDelegate
-(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
    [self.progressView setProgress:progress animated:YES];
}

-(void)loadWebView{
  
    NSMutableURLRequest *newRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.webViewUrl]];
    [self.webView loadRequest:newRequest];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
  
}

- (void)webViewDidFinishLoad:(UIWebView *)webView{

    self.title =  [self.webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    [self.webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
    [self.webView  stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}


@end
